export interface OSSFile {
  name: string
  path: string
  size: number
  type: string
  lastModified: string
  url?: string
  extension: string
}

export interface OSSDirectory {
  name: string
  path: string
}

export interface OSSResponse {
  files: OSSFile[]
  dirs: OSSDirectory[]
  prefix: string
  nextMarker: string
  isTruncated: boolean
  acl: boolean
}

export interface FolderInfo {
  name: string
  path: string
  parent_path: string
  created_time: string
  file_count: number
  folder_count: number
  total_size: number
  is_root: boolean
  full_path: string
}

export interface VideoInfo {
  format: string
  format_long_name: string
  duration: number
  duration_format: string
  size: number
  bitrate: number
  stream_count: number
  video: {
    width: number
    height: number
    codec: string
    codec_long_name: string
    profile: string
    level: number
    fps: string
    frame_count: number
    bitrate: number
    duration: number
    pixel_format: string
    bit_depth: number
    display_aspect_ratio: string
    sample_aspect_ratio: string
    time_base: string
  }
  audio: {
    codec: string
    codec_long_name: string
    channels: number
    channel_layout: string
    sample_rate: number
    sample_format: string
    bitrate: number
    duration: number
    frame_count: number
    time_base: string
  }
  thumbnail: {
    url: string
    width: number
    height: number
  }
}

export interface AudioInfo {
  format: string
  format_long_name: string
  duration: number
  duration_format: string
  size: number
  bitrate: number
  stream_count: number
  audio: {
    codec: string
    codec_long_name: string
    channels: number
    channel_layout: string
    sample_rate: number
    sample_format: string
    bitrate: number
    duration: number
    time_base: string
  }
  metadata?: {
    title?: string
    artist?: string
    album?: string
  }
  waveform?: {
    url: string
  }
  cover?: {
    width: number
    height: number
    url: string
  }
}

export interface FileInfo {
  name: string
  path: string
  url: string
  size: string
  size_format: string
  type: string
  mime_type: string
  extension: string
  created_time: string
  updated_time: string
  etag: string
  storage_class: string
  hash: string
  image_info?: {
    width: string
    height: string
    format: string
    color_mode: string
    animation: number
    quality: number
  }
  original_name: string
  uploader: {
    type: string | null
    id: number | null
    name: string | null
  }
  upload_ip: string
  module: string | null
  purpose: string | null
  remark: string | null
  tags: string[]
  related_id: number | null
  video_info?: VideoInfo
  audio_info?: AudioInfo
}

export interface PreviewInfo {
  url: string
  type: string
  mime_type: string
  size: number
  size_format: string
}

// 文件类型常量
export const FILE_TYPES = {
  IMAGES: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'] as const,
  VIDEOS: ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv'] as const,
  AUDIOS: ['mp3', 'wav', 'ogg', 'aac', 'wma'] as const,
  DOCUMENTS: ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'txt'] as const,
  ARCHIVES: ['zip', 'rar', '7z', 'tar', 'gz'] as const
} as const

// 定义扩展名类型
type ImageExtension = typeof FILE_TYPES.IMAGES[number]
type VideoExtension = typeof FILE_TYPES.VIDEOS[number]
type AudioExtension = typeof FILE_TYPES.AUDIOS[number]
type DocumentExtension = typeof FILE_TYPES.DOCUMENTS[number]
type ArchiveExtension = typeof FILE_TYPES.ARCHIVES[number]
type FileExtension = ImageExtension | VideoExtension | AudioExtension | DocumentExtension | ArchiveExtension

// 获取文件类型
export const getFileType = (extension: string): string => {
  const ext = extension.toLowerCase() as FileExtension
  if ((FILE_TYPES.IMAGES as readonly string[]).includes(ext)) return 'images'
  if ((FILE_TYPES.VIDEOS as readonly string[]).includes(ext)) return 'videos'
  if ((FILE_TYPES.AUDIOS as readonly string[]).includes(ext)) return 'audios'
  if ((FILE_TYPES.DOCUMENTS as readonly string[]).includes(ext)) return 'documents'
  if ((FILE_TYPES.ARCHIVES as readonly string[]).includes(ext)) return 'archives'
  return 'other'
}

// 修改预览类型判断函数
export const isPreviewableType = (type: string, extension: string): boolean => {
  const ext = extension.toLowerCase()
  return (FILE_TYPES.IMAGES as readonly string[]).includes(ext) || 
         (FILE_TYPES.VIDEOS as readonly string[]).includes(ext) || 
         (FILE_TYPES.AUDIOS as readonly string[]).includes(ext)
}

// 获取允许上传的文件类型
export const getAllowedFileTypes = (): string => {
  return [
    ...FILE_TYPES.IMAGES,
    ...FILE_TYPES.VIDEOS,
    ...FILE_TYPES.AUDIOS,
    ...FILE_TYPES.DOCUMENTS,
    ...FILE_TYPES.ARCHIVES
  ].map(ext => `.${ext}`).join(',')
}

// 获取指定类型的允许扩展名
export const getTypeExtensions = (type: string): string[] => {
  switch (type) {
    case 'images':
      return [...FILE_TYPES.IMAGES]
    case 'videos':
      return [...FILE_TYPES.VIDEOS]
    case 'audios':
      return [...FILE_TYPES.AUDIOS]
    case 'documents':
      return [...FILE_TYPES.DOCUMENTS]
    case 'archives':
      return [...FILE_TYPES.ARCHIVES]
    default:
      return []
  }
} 